package vietnam.traveltools;

import vietnam.traveltools.module.LoadingTaskSplash;
import vietnam.traveltools.module.LoadingTaskSplash.LoadingTaskFinishedListener;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar;

public class SplashScreenActivity extends Activity implements LoadingTaskFinishedListener {
	protected boolean _active = true;
	protected int _splashTime = 3000;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.splashscreen_activity);

		// Find the progress bar
        ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
//        ProgressBar cBar = (ProgressBar) findViewById(R.id.cBar);
        // Start your loading
        new LoadingTaskSplash(progressBar, this).execute("www.google.co.uk"); // Pass in whatever you need a url is just an example we don't use it in this tutorial

		
		// thread for displaying the SplashScreen
//		Thread splashTread = new Thread() {
//			@Override
//			public void run() {
//				try {
//					int waited = 0;
//					while (_active && (waited < _splashTime)) {
//						sleep(100);
//						if (_active) {
//							waited += 100;
//						}
//					}
//				} catch (InterruptedException e) {
//					// do nothing
//				} finally {
//					finish();
//					Intent mainIntent = new Intent(SplashScreenActivity.this,
//							MainActivity.class);
//					SplashScreenActivity.this.startActivity(mainIntent);
//					SplashScreenActivity.this.finish();
//				}
//			}
//		};
//		splashTread.start();
		
		
	}
	public void onTaskFinished() {
        completeSplash();
    }
 
    private void completeSplash(){
        startApp();
        finish(); // Don't forget to finish this Splash Activity so the user can't return to it!
    }
 
    private void startApp() {
        Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
        startActivity(intent);
    }
//	@Override
//	public boolean onTouchEvent(MotionEvent event) {
//		if (event.getAction() == MotionEvent.ACTION_DOWN) {
//			_active = false;
//		}
//		return true;
//	}

}

